/*
** op.h for  in /home/georgi_v/rendu/CPE_2013_ed_corewar/asm
** 
** Made by georgi_v
** Login   <georgi_v@epitech.net>
** 
** Started on  Fri Dec  6 17:37:28 2013 georgi_v
** Last update Sat Dec  7 21:11:20 2013 georgi_v
*/

#ifndef _OP_H_
# define _OP_H_

#define MEM_SIZE                (6*1024)
#define IDX_MOD                 512   /* modulo de l'index < */
#define MAX_ARGS_NUMBER         4     /* this may not be changed 2^*IND_SIZE */

#define COMMENT_CHAR            '#'
#define LABEL_CHAR              ':'
#define DIRECT_CHAR             '%'
#define SEPARATOR_CHAR          ','

#define LABEL_CHARS             "abcdefghijklmnopqrstuvwxyz_0123456789"

#define NAME_CMD_STRING         ".name"
#define COMMENT_CMD_STRING      ".comment"

/*
 ** registers
 */

#define REG_NUMBER      16              /* r1 <--> rx */

typedef char    args_type_t;

#define T_REG           1       /* register */
#define T_DIR           2       /* direct instruction (ld #1,r1 put 1 in r1) */
#define T_IND           4       /* always indirect ralative
				   ( ld 1,r1, put r1 what is in address (1+pc)
				   int r1 (4 bytes) */
#define T_LAB           8       /* LABEL */

#define COREWAR_EXEC_MAGIC      0xea83f3        /* why not */

typedef struct	op_s
{
   char         *mnemonique;
   char         nbr_args;
   args_type_t  type[MAX_ARGS_NUMBER];
   char         code;
   int          nbr_cycles;
   char         *comment;
}		op_t;

/*
 ** size
 */

#define IND_SIZE        2               /* bytes */
#define REG_SIZE        4               /* bytes */
#define DIR_SIZE        REG_SIZE        /* bytes */

/*
 ** op_tab
 */

extern  op_t    op_tab[];

/*
 ** header
 */

#define PROG_NAME_LENGTH        128
#define COMMENT_LENGTH          2048

typedef struct	header_s
{
  int	magic;
  char	prog_name[PROG_NAME_LENGTH+1];
  int	prog_size;
  char	comment[COMMENT_LENGTH+1];
}		header_t;

/*
** live
 */

#define CYCLE_TO_DIE    1536    /* number of cycles to be declared dead */
#define CYCLE_DELTA     5
#define NBR_LIVE        40

#endif
